<?php
     // On selectionne tous les lieux
     $aLieuxData = pg_query($oSql, 'SELECT * FROM lieu');
     
    if (isset($_GET['del']))
    {
        // On supprime les dépendances
        pg_query($oSql, "DELETE FROM organisation WHERE edition = '" . $_GET['del'] . "'");
        pg_query($oSql, "DELETE FROM quantite WHERE edition = '" . $_GET['del'] . "'");
        pg_query($oSql, "DELETE FROM match WHERE j1edition = '" . $_GET['del'] . "' OR j2edition = '" . $_GET['del'] . "'");
        pg_query($oSql, "DELETE FROM participation WHERE edition = '" . $_GET['del'] . "'");
        // On supprime le tournoi
        pg_query($oSql, "DELETE FROM tournoi WHERE edition = '" . $_GET['del'] . "'");
    }
    
    if(isset($_POST['type']) && isset($_POST['edition']) && isset($_POST['datedebut']) && isset($_POST['datefin']) && isset($_POST['lieu']))
    {
	if ($_POST['type'] == 'update')
        {
            pg_query($oSql, "UPDATE tournoi SET datedebut = '" . $_POST['datedebut'] . "' , datefin = '" . $_POST['datefin'] . "' , nomlieu = '" . $_POST['lieu'] . "' WHERE edition = '" . $_POST['edition'] . "'");
        }
	else
        {
            pg_query($oSql, "INSERT INTO tournoi VALUES('" . $_POST['edition'] . "','" . $_POST['datedebut'] . "','" . $_POST['datefin'] . "','" . $_POST['lieu'] . "')");
        }
    }    
    
    // On fait la requete de selection globale
    $aTournoiData = pg_query($oSql, 'SELECT * FROM tournoi, lieu WHERE tournoi.nomlieu = lieu.nom');
?>